1 using UnityEngine;
2 using
System;
3 using
System.Collections;
4
5
6 public
class FloatTweenProperty : AbstractTweenProperty, IGenericProperty
7 {
8     
public string propertyName { get; private set; }
9     
private Action<float> _setter;
10     
11     
protected float _originalEndValue;
12     
protected float _startValue;
13     
protected float _endValue;
14     
protected float _diffValue;
15     
16     
17     
public FloatTweenProperty( string propertyName, float endValue, bool isRelative = false ) : base( isRelative )
18     {
19         
this.propertyName = propertyName;
20         _originalEndValue = endValue;
21     }

22     
23
24     ///
<summary>
25     ///
validation checks to make sure the target has a valid property with an accessible setter
26     ///
</summary>
27     
public override bool validateTarget( object target )
28     {
29         
// cache the setter
30         _setter = GoTweenUtils.setterForProperty<Action<
float>>( target, propertyName );
31         
return _setter != null;
32     }
33
34     
35     
public override void prepareForUse()
36     {
37         
// retrieve the getter
38         
var getter = GoTweenUtils.getterForProperty<Func<float>>( _ownerTween.target, propertyName );
39         
40         _endValue = _originalEndValue;
41         
42         
// if this is a from tween we need to swap the start and end values
43         
if( _ownerTween.isFrom )
44         {
45             _startValue = _endValue;
46             _endValue = getter();
47         }
48         
else
49         {
50             _startValue = getter();
51         }
52         
53         
// setup the diff value
54         
if( _isRelative && !_ownerTween.isFrom )
55             _diffValue = _endValue;
56         
else
57             _diffValue = _endValue - _startValue;
58     }
59     
60
61     
public override void tick( float totalElapsedTime )
62     {
63         
var easedValue = _easeFunction( totalElapsedTime, _startValue, _diffValue, _ownerTween.duration );
64         _setter( easedValue );
65     }
66 }



Trò chơi Angry Birds trong UNITY Engine 31.696 lượt xem

Gõ tìm kiếm nhanh...